<template>
  <!-- 新增标签弹窗 -->
  <el-dialog title="新增标签" :visible.sync="dialogVisible" width="30%"
             :before-close="close">
    <el-form ref="form" :rules="rules" :model="form" label-width="80px">
      <el-form-item label="标签名" prop="tagName">
        <el-input v-model="form.tagName"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
            <el-button @click="() => close()">取 消</el-button>
            <el-button type="primary" @click="submit">确 定</el-button>
        </span>
  </el-dialog>
</template>

<script lang="ts">

import {Component, Emit, Prop, Vue} from "vue-property-decorator";
import { Message } from "element-ui";
import { AddTag } from "../../apis/apis";
@Component({
  name: "AddTagDialog",
})
export default class AddTagDialog extends Vue {
  //dialogVisible= {
  //type: Boolean,
  //default: false
  //}
  @Prop({default:false})dialogVisible!: boolean

  form= {
    tagName: ''
  }
  rules={
    tagName: [
      { required: true, message: '请输入标签名', trigger: 'blur' }
    ]
  }


   close():void{
    this.dialogVisible=false;
    console.log("关闭成功");
  }

  submit():void{
    /*
        this.$refs.form.validate((valid: boolean) => {
      if (valid) {
        console.log("submit!");
      } else {
        console.log('error submit!!');
        return false;
      }
    });
    */
   console.log(this.form.tagName);
   
    AddTag(this.form.tagName).then((res: any) =>{
      console.log(res);
      if(res.data.code==='200'){
        Message({
          message: '添加成功',
          type: 'success'
        });
       // this.$emit('addTag');
      }
    }).catch((err) =>{
      console.log(err);
   })

  }
}
</script>


<style scoped>

</style>